<template>
  <div>
    <Button type="success" :to="{path:'order-add',query:{}}">
      添加订单Bom
    </Button>

    <Card style="width:100%">
      <row type="flex" justify="space-between">
        <i-col>

          <span class="key" style="margin-left: 20px">订单号</span>
          <Input v-model="workOrderNo" placeholder="请输入订单号" class="width-condition" style="width: 200px;margin-left: 20px"/>

          <Button type="success"  icon="ios-search" style="margin-left: 50px" @click="find">查询</Button>

        </i-col>
      </row>
    </Card>
    <Table stripe :columns="columns" :data="data"></Table>

    <row style="margin-top: 10px">
  <i-col align="right">
    <Page show-sizer :total="total" show-total @on-change="onChange" @on-page-size-change="onPageSizeChange"/>
  </i-col>
</row>

  </div>
</template>

<script>
  import {OrderBomFindAll,OrderDelete,ProductFindAll} from "../../../api/data"

  export default {
    data() {
      return {
        page: 1,//page 第几页
        pageSize: 10,//pageSize:每页几条数据
        total: 0,
        productList:[],
        workOrderNo:'',
        columns: [
          {
            title: '订单号',
            key: 'workOrderNo'
          },
          {
            title: '产品名称',
            key: 'productName'
          },
          {
            title: '物料',
            key: 'materielNo'
          },
          {
            title: '数量',
            key: 'quantity'
          },
          {
            title: '重量',
            key: 'weight'
          },
          {
            title: '操作',
            key: 'action',
            width: 150,
            align: 'center',
            render: (h, params) => {
              return h('div', [
                h('Button', {
                  props: {
                    type: 'primary',
                    size: 'small'
                  },
                  style: {
                    marginRight: '5px'
                  },
                  on: {
                    click: () => {
                      if (params.row.status !== '已完成'){
                        this.$router.push({
                          path: '/order-setting/order-update', query: {
                            orderNo: params.row.orderNo,
                          }
                        })
                      }else {
                        this.$message.error("当前订单已完成，无法修改！")
                      }
                    }
                  }
                }, '编辑'),
                h('Button', {
                  props: {
                    type: 'error',
                    size: 'small'
                  },
                  on: {
                    click: () => {
                      this.$Modal.confirm({
                        title:'确认删除',
                        content:'是否要删除订单？',
                        onOk:()=>{
                          this.OrderDelete(params.row.orderNo);
                        },
                        onCancel:()=>{}
                      })
                    },
                  }
                }, '删除')

              ]);
            }
          }
        ],
        data: [],
        da:[]
      }
    },
    mounted() {
      this.OrderBomFindAll();
      this.ProductFindAll();
    },
    methods: {
      find(){
        this.OrderBomFindAll();
      },
      OrderBomFindAll() {
        var data = {
          workOrderNo:this.workOrderNo,
          page: this.page,
          pageSize: this.pageSize,
        };
        OrderBomFindAll(data).then(data => {
          if (data.data.code == 0) {
            this.data = data.data.data.list;
            this.total = data.data.data.total;
          }
        })
      },
      ProductFindAll() {
        var data = {
          page: this.page,
          pageSize: 1000,
        };
        ProductFindAll(data).then(data => {
          if (data.data.code == 0) {
            this.productList = data.data.data.list;
          }
        })
      },
      onPageSizeChange(pageSize) {
        this.page = 1;
        this.pageSize = pageSize;
        this.OrderFindAll();
      },
      onChange(page) {
        this.page = page;
        this.OrderFindAll();
      },
      OrderDelete(orderNo){
        let data = {
          orderNo:orderNo
        }
        OrderDelete(data).then(res => {
          if (res.data.code == 0) {
            this.$Message.success("删除成功");
            this.OrderFindAll();
          }else {
            this.$Message.error("删除失败");
          }
        })
      },

      importfxx(obj) {
        let _this = this;
        let inputDOM = this.$refs.inputer;
        // 通过DOM取文件数据
        this.file = event.currentTarget.files[0];
        var rABS = false; //是否将文件读取为二进制字符串
        var f = this.file;
        var reader = new FileReader();
        FileReader.prototype.readAsBinaryString = function(f) {
          var binary = "";
          var rABS = false; //是否将文件读取为二进制字符串
          var pt = this;
          var wb; //读取完成的数据
          var outdata;
          var reader = new FileReader();
          reader.onload = function(e) {
            var bytes = new Uint8Array(reader.result);
            var length = bytes.byteLength;
            for(var i = 0; i < length; i++) {
              binary += String.fromCharCode(bytes[i]);
            }
            var XLSX = require('xlsx');
            if(rABS) {
              wb = XLSX.read(btoa(fixdata(binary)), { //手动转化
                type: 'base64'
              });
            } else {
              wb = XLSX.read(binary, {
                type: 'binary'
              });
            }
            outdata = XLSX.utils.sheet_to_json(wb.Sheets[wb.SheetNames[0]]);//outdata就是你想要的东西
            //outdata就是读取的数据（不包含标题行即表头，表头会作为对象的下标）
            //此处可对数据进行处理
            let arr = [];
            outdata.map(v => {
                let obj = {}
                obj.code = v['材质分类代码']
                obj.name = v['类型代码']
                obj.pro = v['材质代码']
                obj.cit = v['弹簧代码']
                obj.dis = v['规格代码']
                arr.push(obj)
            });
            this.da=arr;
           // _this.da=arr;
            //_this.dalen=arr.length;
           // console.log(this.da.length)
         //   console.log(this.da[0])
          }
          reader.readAsArrayBuffer(f);
        }
        if(rABS) {
          reader.readAsArrayBuffer(f);
        } else {
          reader.readAsBinaryString(f);
        }
      }

    }
  }
</script>

<style lang="less">

</style>

